package com.ukao.steward.pesenter.valetRunners;

import com.ukao.steward.base.BasePresenter;
import com.ukao.steward.bean.BatchToShopBean;
import com.ukao.steward.bean.OrderToShopBean;
import com.ukao.steward.consts.Constant;
import com.ukao.steward.consts.SaveParams;
import com.ukao.steward.retrofit.ApiCallback;
import com.ukao.steward.ui.valetRunners.toShop.ToShopFragment;
import com.ukao.steward.view.valetRunners.ToShopView;

import java.util.HashMap;

import rx.Observable;

/**
 * Created by kefu001 on 2018/4/25.
 * 到店的
 */

public class ToShopPresenter extends BasePresenter<ToShopView>{
   public  ToShopPresenter(ToShopView view){
       super.attachView(view);
   }
    /**
     * 查询到店的订单
     */
    public  void queryToShopCode(String number,final int searchMode){
        mvpView.showLoading();
        HashMap<String,String> mHashMap=new HashMap();
        mHashMap.put("accessToken", SaveParams.getToken());
        Observable observable;
        switch (searchMode){  //orderNo
            case ToShopFragment.BATCH_TO_SHOP_FLAG:
                mHashMap.put("batchCode",number);
                observable= apiStores.queryToShopBatchCode(Constant.createParameter(mHashMap));
                addSubscription(observable,
                        new ApiCallback<BatchToShopBean>() {
                            @Override
                            public void onSuccess(BatchToShopBean model) {
                                //跳转fragment
                                if(model.getHttpCode()==200){
                                    mvpView.onSearchSucceed(model.getData().getId(),model.getData().getCode(), searchMode);
                                }else {
                                    mvpView.showError(model.getMsg());
                                }
                            }
                            //结束
                            @Override
                            public void onFinish() {
                                mvpView.hideLoading(); //隐藏加载
                            }
                        });
                break;
            case ToShopFragment.ORDER_TO_SHOP_FLAG:
                mHashMap.put("orderNo",number);
                observable=apiStores.queryToShopOrderCode(Constant.createParameter(mHashMap));
                addSubscription(observable,
                        new ApiCallback<OrderToShopBean>() {
                            @Override
                            public void onSuccess(OrderToShopBean model) {
                                //跳转fragment
                                if(model.getHttpCode()==200){
                                    mvpView.onSearchSucceed(model.getData().getOrderId(),model.getData().getOrderNo(), searchMode);
                                }else {
                                    mvpView.showError(model.getMsg());
                                }
                            }
                            //结束
                            @Override
                            public void onFinish() {
                                mvpView.hideLoading(); //隐藏加载
                            }
                        });
                break;
        }

    }
}
